package com.kai.steering;

import com.alibaba.druid.util.StringUtils;
import com.kai.steering.common.web.properties.UimpAopProperties;
import lombok.extern.java.Log;
import org.mybatis.spring.annotation.MapperScan;
import org.omg.CORBA.Environment;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @ Author     ：LiuKai.
 * @ Date       ：Created in 16:05 2022-2-25
 * @ Description：启动类
 * @ Modified By：
 * @Version:
 */
@SpringBootApplication
@MapperScan({"com.kai.steering.**.mapper"})
@EnableConfigurationProperties(UimpAopProperties.class)

@EnableTransactionManagement
@EnableSwagger2
@EnableScheduling //开启定时任务
@Log

public class DataBusApplication extends SpringBootServletInitializer {
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext context = SpringApplication.run(DataBusApplication.class, args);
        ConfigurableEnvironment env = context.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }


        log.info("\n----------------------------------------------------------\n\t" +
                "swagger访问地址: \thttp://localhost:" + port + path +"/swagger-ui.html"+ "\n\t" +
                "访问访问地址: \t\thttp://localhost:" + port + path + "\n\t" +
                "IP访问访问地址: \t\thttp://" + ip + ":" + port + path + "\n\t" +
                "----------------------------------------------------------");

    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DataBusApplication.class);
    }
}
